HA$PBExportHeader$u_cst_grillamaincabedet.sru
forward
global type u_cst_grillamaincabedet from userobject
end type
type dw_4 from datawindow within u_cst_grillamaincabedet
end type
type dw_3 from datawindow within u_cst_grillamaincabedet
end type
type dw_2 from datawindow within u_cst_grillamaincabedet
end type
type dw_1 from u_dw within u_cst_grillamaincabedet
end type
end forward

global type u_cst_grillamaincabedet from userobject
integer width = 1979
integer height = 2300
long backcolor = 67108864
string text = "none"
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
event resize pbm_size
event ue_refrescar_row ( datawindow as_dw,  integer ai_row,  string as_button )
event ue_activa_opc ( boolean ab_activa_dw )
event ue_getbutton ( string as_button )
event ue_actualizar ( )
event ue_refrescar_row2 ( datawindow as_dwcabe,  datawindow as_dwdet,  integer ai_row,  string as_button )
event ue_bloquear_refrescar ( boolean ab_param )
dw_4 dw_4
dw_3 dw_3
dw_2 dw_2
dw_1 dw_1
end type
global u_cst_grillamaincabedet u_cst_grillamaincabedet

type variables
long il_id ,il_ModifiedCount=0
integer ii_tool , ii_sw=0 ,ii_codigo
STRING is_button,is_tabla,is_codigo
boolean ib_sw = false, ib_refresh = false,ib_consulta = false
s_parm istr_parm
datastore ids_datastore
//u_cst_m_toolcabemain    iuo_toolcabemain
window iw_parent


u_cst_toolbarstrip iuo_toolbar
//u_cst_grillamain iuo_grillamain
u_cst_tabmantocabedet iuo_tabmantomain

userobject iuo_grilla
end variables

forward prototypes
public function integer of_getwindow ()
public subroutine of_filtrar (string cadena, string columna)
public subroutine of_siguiente ()
public subroutine of_anterior ()
public subroutine of_primero ()
public subroutine of_ultimo ()
public function string of_getid ()
public subroutine of_retrieve ()
public subroutine of_setparam (ref integer ai_parm1, integer ai_parm2, integer ai_parm3, integer ai_parm4)
end prototypes

event resize;dw_1.Resize(newWidth, newHeight)
end event

event ue_refrescar_row(datawindow as_dw, integer ai_row, string as_button);integer li_fila 
choose case upper(as_button)
	case 'EDITAR','CONSULTAR'
		dw_1.object.data[ai_row] =as_dw.object.data 
	case 'NUEVO'
		//dw_1.accepttext( )
		ib_refresh = true
		dw_1.scrolltorow(dw_1.insertrow(0))
		dw_1.object.data[DW_1.ROWCOUNT()] = as_dw.object.data []
		ib_refresh = false
end choose

end event

event ue_activa_opc(boolean ab_activa_dw);
ib_sw = ab_activa_dw

//ib_refresh = ab_activa_dw

end event

event ue_getbutton(string as_button);is_button = as_button
end event

event ue_actualizar();
of_retrieve()


end event

event ue_refrescar_row2(datawindow as_dwcabe, datawindow as_dwdet, integer ai_row, string as_button);integer li_fila 
choose case upper(as_button)
	case 'EDITAR','CONSULTAR','ANULAR'
		ib_refresh=true
		dw_1.object.data[ai_row] = as_dwCabe.object.data
		//dw_1.object.data = as_dwCabe.object.data
		dw_3.object.data =as_dwDet.object.data 
		ib_refresh=false
	case 'NUEVO'
		//dw_1.accepttext( )
		ib_refresh = true
		dw_1.scrolltorow(dw_1.insertrow(0))
		dw_1.object.data[DW_1.ROWCOUNT()] = as_dwCabe.object.data []
		//ue_setRow
		iuo_tabmantomain.Dynamic Event  ue_setRow(DW_1.ROWCOUNT()) 
		//DW_1.ROWCOUNT()
		for li_fila = 1 to as_dwDet.rowcount()
			dw_3.scrolltorow(dw_3.insertrow(0))
			dw_3.object.data[dw_3.rowcount()] = as_dwDet.object.data [li_fila]
		next
		
		dw_2.scrolltorow(dw_2.insertrow(0))
		dw_2.object.data[DW_2.ROWCOUNT()] = as_dwCabe.object.data []
		
		for li_fila = 1 to as_dwDet.rowcount()
			dw_4.scrolltorow(dw_4.insertrow(0))
			dw_4.object.data[dw_4.rowcount()] = as_dwDet.object.data [li_fila]
		next
		ib_refresh = false
		
end choose

end event

event ue_bloquear_refrescar(boolean ab_param);ib_refresh = ab_param
end event

public function integer of_getwindow (); PowerObject	lpo_parent
Window lw_window

// loop thru parents until a window is found
lpo_parent = GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid(lpo_parent)
	lpo_parent = lpo_parent.GetParent()
Loop

// set return to the window or null if not found
If IsValid (lpo_parent) Then
	lw_window = lpo_parent
Else
	SetNull(lw_window)
End If

iw_parent = lw_window

RETURN 1
end function

public subroutine of_filtrar (string cadena, string columna);string ls_cad,ls_tipo,ls_col
if cadena = ""  then
		this.dw_1.SetFilter("")
else
		ls_col = this.dw_1.describe(columna+'.name')
		ls_tipo=this.dw_1.describe(ls_col+'.coltype')
		ls_cad = 'Upper(string('+ls_col+')) like "%'+Upper(cadena)+'%" '
		this.dw_1.SetFilter(ls_cad)	
end if
this.dw_1.filter()
end subroutine

public subroutine of_siguiente ();dw_1.scrollnextrow( )
end subroutine

public subroutine of_anterior ();dw_1.scrollpriorrow( )
end subroutine

public subroutine of_primero ();dw_1.scrolltorow(0)
end subroutine

public subroutine of_ultimo ();dw_1.scrolltorow(dw_1.rowcount( ) )
end subroutine

public function string of_getid ();
string ls_data
if  dw_1.rowcount() <=0  then return ''
ls_data = dw_1.object.data[dw_1.getrow(),1]
return ls_data
end function

public subroutine of_retrieve ();INTEGER ai_tienda,ai_alma,ai_periodo
setpointer( HourGlass!)
choose case upper(is_tabla)
	case 'MMOVIMIENTO','VTADOCU'
		dw_1.retrieve(istr_parm.integer_parm[1],istr_parm.integer_parm[2],istr_parm.integer_parm[4],istr_parm.integer_parm[3])
		dw_3.retrieve(istr_parm.integer_parm[1],istr_parm.integer_parm[2],istr_parm.integer_parm[4],istr_parm.integer_parm[3])

	case 'MMODULO_MUSER'	
		dw_1.retrieve()
		if gs_iduser<> 'sa' then
			dw_1.setfilter( 'binstall = 1'); dw_1.filter()
		else
			dw_1.setfilter( ''); dw_1.filter()
		end if
		dw_3.retrieve()
		
	case else
		dw_1.retrieve()
		dw_3.retrieve()

END CHOOSE
commit;
setpointer( Arrow!)
end subroutine

public subroutine of_setparam (ref integer ai_parm1, integer ai_parm2, integer ai_parm3, integer ai_parm4);//istr_parm = apo_parm

istr_parm.integer_parm[1] = ai_parm1
istr_parm.integer_parm[2]= ai_parm2
istr_parm.integer_parm[3]= ai_parm3
istr_parm.integer_parm[4]= ai_parm4
//
end subroutine

on u_cst_grillamaincabedet.create
this.dw_4=create dw_4
this.dw_3=create dw_3
this.dw_2=create dw_2
this.dw_1=create dw_1
this.Control[]={this.dw_4,&
this.dw_3,&
this.dw_2,&
this.dw_1}
end on

on u_cst_grillamaincabedet.destroy
destroy(this.dw_4)
destroy(this.dw_3)
destroy(this.dw_2)
destroy(this.dw_1)
end on

event constructor;string ls_dw ,is_tool,ls_dwdet

of_getwindow()

dw_1.Sort()
dw_1.Event RetrieveEnd(dw_1.RowCount())
dw_1.Event RowFocusChanged(1)

istr_parm        = message.powerobjectparm
iuo_toolbar 		=  istr_parm.auo_toolbarstrip
ids_datastore   = istr_parm.ads_menu
iuo_tabmantomain = istr_parm.auo_tabmantocabedet
ls_dw              = ids_datastore.object.tDwGrid[1]
is_tabla           = ids_datastore.object.tTabla[1]
ls_dwdet          = ids_datastore.object.tDwGrid2[1]
//if isnull(ls_dw) or ls_dw = '' then return 
//iuo_toolcabemain =  istr_parm.auo_toolcabemain
//iuo_toolcabemain = create u_cst_m_toolcabemain

if is_tabla = 'MMODULO_MUSER' then
	if gs_iduser = 'sa' then
		dw_1.dataobject = ls_dw
		dw_3.dataobject =ls_dwdet
		dw_1.settransobject( sqlca);dw_3.settransobject( sqlca);
		dw_2.dataobject =ls_dw ; dw_4.dataobject =ls_dwdet

	else
		dw_1.dataobject ='d_mmodulo_user_grid'
		dw_3.dataobject =ls_dwdet
		dw_1.settransobject( sqlca);dw_3.settransobject( sqlca);
		dw_2.dataobject ='d_mmodulo_user_grid' ; dw_4.dataobject =ls_dwdet

		
	end if
else
	dw_1.dataobject =ls_dw
	dw_3.dataobject =ls_dwdet
	dw_1.settransobject( sqlca);dw_3.settransobject( sqlca);
	dw_2.dataobject =ls_dw ; dw_4.dataobject =ls_dwdet

end if
iuo_toolbar.DYNAMIC post event ue_cargar_columnas(dw_1)
of_retrieve()
//dw_1.retrieve();commit;	 
//dw_3.retrieve();commit;	

end event

type dw_4 from datawindow within u_cst_grillamaincabedet
boolean visible = false
integer x = 1093
integer y = 532
integer width = 686
integer height = 400
integer taborder = 30
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_3 from datawindow within u_cst_grillamaincabedet
boolean visible = false
integer x = 585
integer y = 244
integer width = 686
integer height = 400
integer taborder = 20
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_2 from datawindow within u_cst_grillamaincabedet
boolean visible = false
integer x = 571
integer y = 1040
integer width = 686
integer height = 400
integer taborder = 20
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_1 from u_dw within u_cst_grillamaincabedet
event ue_scrollvertical ( )
event ue_refresh ( )
event ue_scrolltorow ( integer ai_find )
integer width = 1957
integer height = 2280
integer taborder = 10
boolean hscrollbar = true
boolean vscrollbar = true
end type

event ue_scrollvertical();long ll_row
string ls_row

// Obtenga la primera fila de la p$$HEX1$$e100$$ENDHEX$$gina (FirstRowOnPage) sobre el datawindow
// primario. Dado que es un datawindow free form con una sola fila desplegada,
// la primera fila es la $$HEX1$$fa00$$ENDHEX$$nica visible. Despl$$HEX1$$e100$$ENDHEX$$cese hacia esa misma fila en el
// datawindow secundario.
//ls_row = this.Object.DataWindow.FirstRowOnPage
//ll_row = integer(ls_row)
//iuo_toolcabemain.DYNAMIC event ue_scroll(ll_row)
//dw_secondary.ScrollToRow(ll_row)
end event

event ue_refresh();integer li_codigo
string ls_codigo


dw_2.reset();dw_4.reset()
dw_1.RowsCopy(dw_1.GetRow(),dw_1.GetRow(), primary!, dw_2, 1, Primary!)

choose case UPPER(is_tabla)
	case 'MMODULO_MUSER'
		ls_codigo =dw_1.object.data[dw_1.GetRow(),1]
		is_codigo = ls_codigo
		dw_3.setfilter('idmodulo="'+ls_codigo+'"');dw_3.filter()
	case 'MTOOLBARBUTTON'
		ls_codigo =dw_1.object.data[dw_1.GetRow(),1]
		is_codigo = ls_codigo
		dw_3.setfilter('idtoolbar="'+ls_codigo+'"');dw_3.filter()	
//	case 'MUSERALMA'
//		li_codigo =dw_1.object.data[dw_1.GetRow(),1]
//		ii_codigo=li_codigo
//		dw_3.setfilter('string(idalma)=' + String( li_codigo));dw_3.filter()
	case else
		li_codigo =dw_1.object.data[dw_1.GetRow(),1]
		ii_codigo=li_codigo
		dw_3.setfilter("#1=" + String( li_codigo));dw_3.filter()
end choose

dw_3.SetSort("#1 A, #2 A");dw_3.sort( )
dw_3.RowsCopy(dw_3.GetRow(), dw_3.RowCount(), Primary!, dw_4, 1, Primary!)
//dw_3.RowsCopy(dw_3.GetRow(),dw_3.GetRow(), primary!, dw_4, 1, Primary!)
//if dw_2.rowcount() > 0 then

iuo_tabmantomain.Dynamic Event  ue_cambio_opc('CONSULTAR') 
iuo_tabmantomain.Dynamic Event  ue_bloquear_dwdet() 
iuo_tabmantomain.Dynamic post Event  ue_copy_fila(dw_2,dw_1.GetRow(),1)
iuo_tabmantomain.Dynamic post Event  ue_copy_fila_det(dw_4,dw_1.GetRow(),1)
ib_consulta =true
ib_sw = false ; il_ModifiedCount=0
//end if
end event

event ue_scrolltorow(integer ai_find);this.scrolltorow( ai_find)
ib_refresh = false
end event

event constructor;call super::constructor;// load sort service


If this.of_StartService("GridStyle") Then
	iSrv_GridStyle.of_SetStyle(True, True, True, True)

//	iSrv_GridStyle.of_AddAutoWidth("idgmenu")
//	iSrv_GridStyle.of_AddAutoWidth("id_name")
//	iSrv_GridStyle.of_AddAutoWidth("address")
//	iSrv_GridStyle.of_AddAutoWidth("city")
//	iSrv_GridStyle.of_AddAutoWidth("state")
//	iSrv_GridStyle.of_AddAutoWidth("company_name")

End If

// load selectrow service
If this.of_StartService("Select") Then
	iSrv_Select.of_SetSelectStyle("extend")
End If

end event

event doubleclicked;call super::doubleclicked;//if row > 0  then
//	iuo_toolbar.DYNAMIC event UE_BUTTONCLICKED('EDITAR')
//end if
//


end event

event scrollvertical;call super::scrollvertical;this.event post ue_scrollvertical()
end event

event clicked;call super::clicked;
if row > 0  and il_ModifiedCount = 0 then // ib_sw = false then
	
	if ib_refresh then return
//	if ib_consulta then return
	if dw_1.rowcount() = 1 then
	  this.event ue_refresh ()
	end if
end if
end event

event rowfocuschanged;//select rows
INTEGER li_verificar,li_find
If IsValid(iSrv_Select) Then
	iSrv_Select.Event RowFocusChanged(currentrow)
	If dw_1.rowcount() > 0 Then
		if ib_refresh then return
		il_ModifiedCount = iuo_tabmantomain.Dynamic Event ue_getdwmodified()
		if ib_sw and il_ModifiedCount > 0  then
			
			Choose Case iuo_tabmantomain.Dynamic Event ue_verificar_modified('')
				Case 3
					li_find = this.find('String(#1)="'+String(ii_codigo)+'"' ,1,dw_1.rowcount())
					
					post event ue_scrolltorow( li_find)
					ib_refresh = true
					return
				Case 2 
					il_ModifiedCount = 0
			End Choose
		end if
		If il_ModifiedCount = 0 then//ib_sw = False and
		   this.event  ue_refresh ()
		End If
	End If 
End If

end event

